﻿using System;
using System.Data;
using System.Collections.Generic;
using Youz.Common.Entity;
using Youz.Common.DAL;
using Youz.Common.BLL;

namespace Youz.Common.BLL
{
	/// <summary>
	/// 假日设置
	/// </summary>
    public partial class Sys_HolidayBLL : BaseBLL
	{
        private readonly Sys_HolidayDAL dal = new Sys_HolidayDAL();

		public Sys_HolidayBLL()
		{
            base.MenuName = "系统管理";
            base.ModuleName = "假日设置";
        }

		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(DateTime holidayDate)
		{
            return dal.Exists(holidayDate);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
        public string Add(Youz.Common.Entity.Sys_Holiday model)
        {
            
            if (Exists(model.HolidayDate))
            {
                return Utility.AjaxResult(false, "日期已經存在！");
            }
            bool result = dal.Add(model);
            WriteOperationLog(OperationType.Add, result, model.HolidayID.ToString());
            return Utility.AjaxResult(result);
        }

		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(Youz.Common.Entity.Sys_Holiday model)
        {
            bool result = dal.Update(model);
            WriteOperationLog(OperationType.Update, result, model.HolidayID.ToString());
            return result;
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid holidayID)
		{
            bool result = dal.Delete(holidayID);
            WriteOperationLog(OperationType.Delete, result,Convert.ToString(holidayID));
            return result;
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string HolidayIDlist )
		{
            bool result = dal.DeleteList(HolidayIDlist);
            WriteOperationLog(OperationType.Delete, result, HolidayIDlist);
            return result;
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Youz.Common.Entity.Sys_Holiday GetModel(Guid HolidayID)
		{
			
			return dal.GetModel(HolidayID);
		}

		
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Youz.Common.Entity.Sys_Holiday> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Youz.Common.Entity.Sys_Holiday> DataTableToList(DataTable dt)
		{
			List<Youz.Common.Entity.Sys_Holiday> modelList = new List<Youz.Common.Entity.Sys_Holiday>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Youz.Common.Entity.Sys_Holiday model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataTable GetAllList()
		{
			return null;
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
        
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
        public string GetPager(int PageIndex, int PageSize, string holidayTitle, string holidayDate)
        {
            int total;
            DataTable dt = dal.GetPager(PageIndex, PageSize, holidayTitle, holidayDate,out total);         
            return Utility.GetJsonByDataTableHaveTime(total,dt);
        }       
		#endregion  BasicMethod

		#region  ExtensionMethod
        /// <summary>
        /// 獲取兩個日期間的有效天數
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public int GetValidDays(DateTime startDate, DateTime endDate)
        {
            return dal.GetValidDays(startDate, endDate);
        }
        /// <summary>
        /// 判断是否为节假日
        /// </summary>
        /// <returns></returns>
        public DataTable IsHoliday()
        {
            return dal.IsHoliday(ConfigParameters.SysTime);
        }

        public Sys_Holiday Get(DateTime HolidayDate)
        {
            return dal.Get(HolidayDate);
        }
		#endregion  ExtensionMethod
	}
}

